| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import chai, { expect } from 'chai'; |
||
| 10 | describe('Album', () => { |
||
| 11 | let spotify; |
||
| 12 | let stubedFetch; |
||
| 13 | |||
| 14 | beforeEach( () => { |
||
| 15 | spotify = new SpotifyWrapper({ |
||
| 16 | token: 'foo', |
||
| 17 | }); |
||
| 18 | |||
| 19 | stubedFetch = sinon.stub(global, 'fetch'); |
||
| 20 | stubedFetch.resolves({ json: () => ({ album: 'name' }) }); |
||
| 21 | }); |
||
| 22 | |||
| 23 | afterEach( () => { |
||
| 24 | stubedFetch.restore(); |
||
| 25 | }); |
||
| 26 | |||
| 27 | describe('smoke tests', () => { |
||
| 28 | it('should have getAlbum method', () => { |
||
| 29 | expect(spotify.album.getAlbum).to.exist; |
||
|
|
|||
| 30 | }); |
||
| 31 | |||
| 32 | it('should have getAlbums method', () => { |
||
| 33 | expect(spotify.album.getAlbums).to.exist; |
||
| 34 | }); |
||
| 35 | |||
| 36 | it('should have getAlbumTracks method', () => { |
||
| 37 | expect(spotify.album.getTracks).to.exist; |
||
| 38 | }); |
||
| 39 | }); |
||
| 40 | |||
| 41 | describe('getAlbum', () => { |
||
| 42 | it('should call fetch method', () => { |
||
| 43 | spotify.album.getAlbum(); |
||
| 44 | expect(stubedFetch).to.have.been.calledOnce; |
||
| 45 | }); |
||
| 46 | |||
| 47 | it('should call fetch with the correct URL', () => { |
||
| 48 | spotify.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTy'); |
||
| 49 | expect(stubedFetch).to.have.been |
||
| 50 | .calledWith('https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy'); |
||
| 51 | |||
| 52 | spotify.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTk') |
||
| 53 | expect(stubedFetch).to.have.been |
||
| 54 | .calledWith('https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTk'); |
||
| 55 | }); |
||
| 56 | |||
| 57 | it('should return the correct data from Promise', () => { |
||
| 58 | const album = spotify.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTy'); |
||
| 59 | album.then((data) => { |
||
| 60 | expect(data).to.be.eql({ album: 'name' }); |
||
| 61 | }) |
||
| 62 | }); |
||
| 63 | }); |
||
| 64 | |||
| 65 | describe('getAlbums', () => { |
||
| 66 | it('should call fetch method', () => { |
||
| 67 | spotify.album.getAlbums(); |
||
| 68 | expect(stubedFetch).to.have.been.calledOnce; |
||
| 69 | }); |
||
| 70 | |||
| 71 | it('should call fetch with the correct URL', () => { |
||
| 72 | spotify.album.getAlbums(['4aawyAB9vmqN3uQ7FjRGTy', '4aawyAB9vmqN3uQ7FjRGTk']); |
||
| 73 | expect(stubedFetch).to.have.been |
||
| 74 | .calledWith('https://api.spotify.com/v1/albums/?ids=4aawyAB9vmqN3uQ7FjRGTy,4aawyAB9vmqN3uQ7FjRGTk'); |
||
| 75 | }); |
||
| 76 | |||
| 77 | it('should return the correct data from Promise', () => { |
||
| 78 | const albums = spotify.album.getAlbums(['4aawyAB9vmqN3uQ7FjRGTy', '4aawyAB9vmqN3uQ7FjRGTk']); |
||
| 79 | albums.then((data) => { |
||
| 80 | expect(data).to.be.eql({ album: 'name' }); |
||
| 81 | }); |
||
| 82 | }); |
||
| 83 | }); |
||
| 84 | |||
| 85 | describe('getAlbumsTracks', () => { |
||
| 86 | it('should call fetch method', () => { |
||
| 87 | spotify.album.getTracks(); |
||
| 88 | expect(stubedFetch).to.have.been.calledOnce; |
||
| 89 | }); |
||
| 90 | |||
| 91 | it('should call fetch with the correct URL', () => { |
||
| 92 | spotify.album.getTracks('4aawyAB9vmqN3uQ7FjRGTy'); |
||
| 93 | expect(stubedFetch).to.have.been |
||
| 94 | .calledWith('https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy/tracks'); |
||
| 95 | }); |
||
| 96 | |||
| 97 | it('should return the correct data from Promise', () => { |
||
| 98 | const tracks = spotify.album.getTracks('4aawyAB9vmqN3uQ7FjRGTy'); |
||
| 99 | tracks.then((data) => { |
||
| 100 | expect(data).to.be.eql({ album: 'name' }); |
||
| 101 | }); |
||
| 102 | }); |
||
| 103 | }); |
||
| 104 | }); |
||
| 105 |